const a = /[&<>"']/,
  g = new RegExp(a.source, 'g'),
  f = /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,
  h = new RegExp(f.source, 'g'),
  d = {
    '&': '&amp;',
    '<': '&lt;',
    '>': '&gt;',
    '"': '&quot;',
    "'": '&#39;',
  },
  u = t => d[t];
function x(t, n) {
  if (n) {
    if (a.test(t)) return t.replace(g, u);
  } else if (f.test(t)) return t.replace(h, u);
  return t;
}
const w = /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/gi;
function C(t) {
  return t.replace(
    w,
    (n, r) => (
      (r = r.toLowerCase()),
      r === 'colon'
        ? ':'
        : r.charAt(0) === '#'
          ? r.charAt(1) === 'x'
            ? String.fromCharCode(parseInt(r.substring(2), 16))
            : String.fromCharCode(+r.substring(1))
          : ''
    ),
  );
}
const R = /(^|[^\[])\^/g;
function m(t, n) {
  let r = typeof t == 'string' ? t : t.source;
  n = n || '';
  const e = {
    replace: (c, s) => {
      let l = typeof s == 'string' ? s : s.source;
      return (l = l.replace(R, '$1')), (r = r.replace(c, l)), e;
    },
    getRegex: () => new RegExp(r, n),
  };
  return e;
}
function E(t) {
  try {
    t = encodeURI(t).replace(/%25/g, '%');
  } catch {
    return null;
  }
  return t;
}
const A = { exec: () => null };
function T(t, n) {
  const r = t.replace(/\|/g, (s, l, p) => {
      let i = !1,
        o = l;
      for (; --o >= 0 && p[o] === '\\'; ) i = !i;
      return i ? '|' : ' |';
    }),
    e = r.split(/ \|/);
  let c = 0;
  if (
    (e[0].trim() || e.shift(),
    e.length > 0 && !e[e.length - 1].trim() && e.pop(),
    n)
  )
    if (e.length > n) e.splice(n);
    else for (; e.length < n; ) e.push('');
  for (; c < e.length; c++) e[c] = e[c].trim().replace(/\\\|/g, '|');
  return e;
}
function y(t, n, r) {
  const e = t.length;
  if (e === 0) return '';
  let c = 0;
  for (; c < e; ) {
    const s = t.charAt(e - c - 1);
    if (s === n && !r) c++;
    else if (s !== n && r) c++;
    else break;
  }
  return t.slice(0, e - c);
}
function S(t, n) {
  if (t.indexOf(n[1]) === -1) return -1;
  let r = 0;
  for (let e = 0; e < t.length; e++)
    if (t[e] === '\\') e++;
    else if (t[e] === n[0]) r++;
    else if (t[e] === n[1] && (r--, r < 0)) return e;
  return -1;
}
export {
  E as cleanUrl,
  m as edit,
  x as escape,
  S as findClosingBracket,
  A as noopTest,
  y as rtrim,
  T as splitCells,
  C as unescape,
};
